﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace VFCons
{
	public partial class FTLightControl : UserControl
	{
		public event EventHandler LightCmdClick;
		public event EventHandler LightCmdScroll;

		public FTLightControl()
		{
			InitializeComponent();
			trackBar_lightbrightA.Minimum = 6;
			trackBar_lightbrightB.Minimum = 6;
			label_LightAmin.Text = "Min:" + Convert.ToString(trackBar_lightbrightA.Minimum);
			label_LightBmin.Text = "Min:" + Convert.ToString(trackBar_lightbrightB.Minimum);
			label_ValueA.Text = Convert.ToString(trackBar_lightbrightA.Value);
			label_ValueB.Text = Convert.ToString(trackBar_lightbrightB.Value);
			label_LightAmax.Text = "Max:" + Convert.ToString(trackBar_lightbrightA.Maximum);
			label_LightBmax.Text = "Max:" + Convert.ToString(trackBar_lightbrightB.Maximum);

			button_LightAset.Click += Buttons_Click;
			button_LightBset.Click += Buttons_Click;
			buootn_LightonA.Click += Buttons_Click;
			buootn_LightoffA.Click += Buttons_Click;
			buootn_LightonB.Click += Buttons_Click;
			buootn_LightoffB.Click += Buttons_Click;
			trackBar_lightbrightA.Scroll += trackBars_Scroll;
			trackBar_lightbrightB.Scroll += trackBars_Scroll;
		}

		public ushort Light_LimitA;//A灯限制
		public ushort Light_LimitB;//B灯限制

		private void trackBars_Scroll(object sender, EventArgs e)
		{
			if (LightCmdScroll != null) LightCmdScroll(sender, e);
		}

		private void Buttons_Click(object sender, EventArgs e)
		{
			Button btn = sender as Button;
			if (btn.Name == "button_LightAset")
			{
				try
				{
					Light_LimitA = Convert.ToUInt16(textBox_LightAvalue.Text);
					if (Light_LimitA > 999 || Light_LimitA < 6)
					{
						MessageBox.Show("超过可设置范围", "ERROR");
					}
					else
					{
						trackBar_lightbrightA.Maximum = Light_LimitA;
					}
				}
				catch (Exception ex)
				{
					MessageBox.Show("只能输入整数" + ex.Message,"ERROR");
				}
			}
			else if (btn.Name == "button_LightBset")
			{
				try
				{
					Light_LimitB = Convert.ToUInt16(textBox_LightBvalue.Text);
					if (Light_LimitB > 999 || Light_LimitB < 6)
					{
						MessageBox.Show("超过可设置范围", "ERROR");
					}
					else
					{
						trackBar_lightbrightB.Maximum = Light_LimitB;
					}
				}
				catch (Exception ex)
				{
					MessageBox.Show("只能输入整数" + ex.Message,"ERROR");
				}
			}
			if (LightCmdClick != null) LightCmdClick(sender, e);
		}

		

	}
}
